package com.fairytask.ui
{
	import com.fairytask.engine.components.ToolTips;
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.engine.resource.StaticIni;
	import com.jzonl.managers.TipsManage;
	import com.jzonl.net.messages.CustomToServerFlag;
	import com.jzonl.net.mgr.NetMgr;
	import com.fairytask.ui.base.FrameUI;
	import com.fairytask.ui.effect.MoneyEffect;
	
	import flash.events.MouseEvent;
	
	/**
	 * 通缉榜任务窗口 
	 * @author pangj
	 * 
	 */
	public class WantedTaskUI extends FrameUI
	{
		public var taskID       :String;    //任务ID
		public var taskStatus   :int;       //任务状态
		public var taskTrait    :int;       //任务品质，显示不同的颜色
		public var taskImg      :Clip;      //任务图片
		public var taskName     :Label;     //任务名称
		public var taskBtn      :Button;    //任务按钮
		public var isComplete   :Clip;      //完成图戳
		
		public  var _moneyEffect	:MoneyEffect;
		
		/**
		 *任务显示窗口 构造方法 
		 * @param id       任务ID
		 * @param status   任务状态
		 * @param color    任务品质
		 * @param popUI
		 * 
		 */
		public function WantedTaskUI(id:String,status:int,color:int,popUI:Boolean=true)
		{
			super(popUI);
			taskID = id;
			taskStatus = status;
			taskTrait = color;
			initTask();
			initEvent();
		}
		private function initTask():void
		{
			taskImg.source = ResConfig.pngTaskPath+StaticIni.getIniVar(taskID,"Photo")+ResConfig.photoImg;
			taskImg.height = 120;
			taskImg.width = 100;
			isComplete.visible = false;
			setName();
			setBtn();
		}
		private function initEvent():void
		{
			taskBtn.addEventListener(MouseEvent.CLICK,onClick);
			taskImg.addEventListener(MouseEvent.ROLL_OVER,function(evt:MouseEvent):void
			{
				TipsManage.showTips(StaticIni.getSwfLangStr("TaskName_"+taskID));
			});
			taskImg.addEventListener(MouseEvent.ROLL_OUT,function(evt:MouseEvent):void
			{
				ToolTips.hide();
			});
		}
		/**
		 * 单击任务按钮
		 * 
		 */
		private function onClick(eve:MouseEvent):void
		{
			switch(taskStatus)
			{            //任务状态->按钮显示
				case -1://失败
				{
					break;
				}
				case 0://未接----->接取
				{
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_TASK_CONFIRM_ACCEPT,int(taskID));
					break;
				}
				case 1://完成 ----->完成
				{
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_TASK_CONFIRM_SUBMIT,int(taskID));
					if ((taskTrait == WantedListUI.Max_TRAIT) || (taskTrait == WantedListUI.Max_TRAIT-1) || taskTrait == (WantedListUI.Max_TRAIT-2))
						WantedListUI.getInstance().setOrigin(this.x+50,this.y+50);
					break;
				}
				case 2://已接----->放弃
				{
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_DAILY_TASK_GIVE_UP,int(taskID));
					break;
				}
				case 3://已领奖---->已完成
				{
					break;
				}
			}
		}
		/**
		 * 根据任务品质设置任务名称颜色 
		 * 
		 */
		public function setName():void
		{
			taskName.htmlStrByBorder = StaticIni.getSwfLangStr("TaskName_"+taskID);
			taskName.x = (windowBG.width - taskName.width)/2;
			switch(taskTrait)
			{
				case WantedListUI.TASK_TRAIT_WHITE:
				{
					taskName.color = WantedListUI.BOX_COLOR_WHITE;
					break;
				}
				case WantedListUI.TASK_TRAIT_GREEN:
				{
					taskName.color = WantedListUI.BOX_COLOR_GREEN;
					break;
				}
				case WantedListUI.TASK_TRAIT_BLUE:
				{
					taskName.color = WantedListUI.BOX_COLOR_BLUE;
					break;
				}
				case WantedListUI.TASK_TRAIT_PURPLE:
				{
					taskName.color = WantedListUI.BOX_COLOR_PURPLE;
					break;
				}
				case WantedListUI.TASK_TRAIT_ORANGE:
				{
					taskName.color = WantedListUI.BOX_COLOR_ORANGE;
					break;
				}
				case WantedListUI.TASK_TRAIT_GOLDEN:
				{
					taskName.color = WantedListUI.BOX_COLOR_GOLDEN;
					break;
				}
			}
		}
		/**
		 * 根据任务状态设置按钮
		 * 
		 */
		public function setBtn():void
		{
			//taskBtn.mouseEnabled = true;
			switch(taskStatus)
			{
				case -1:
				{
					taskBtn.skin = "";
					break;
				}
				case 0://蓝 接取
				{
					taskBtn.label=StaticIni.getSwfLangStr("1000000291");
					taskBtn.skin = "button_034";
					break;
				}
				case 1://黄 完成
				{
					taskBtn.label=StaticIni.getSwfLangStr("1000000293");
					taskBtn.skin = "button_034";
					break;
				}
				case 2://红 放弃
				{
					taskBtn.label=StaticIni.getSwfLangStr("1000000292");
					taskBtn.skin = "button_034";
					break;
				}
				case 3://绿 已完成
				{
					taskBtn.skin = "button_052";
					//taskBtn.label=StaticIni.getSwfLangStr("Task_Completed");
					//taskBtn.mouseEnabled = false;
					taskBtn.btnCanMouse = false;
					isComplete.visible = true;
					break;
				}
			}
		}
		
	}
}